<template>
  <div>
    <el-tabs v-model="activeName" style="width: 760px">
      <el-tab-pane label="基本设置" name="first">
        <el-form ref="form" :rules="rules" :model="step" label-width="150px">
          <el-form-item label="步骤名称" prop="name">
            <el-input v-model="step.name" placeholder="请输入步骤名称"></el-input>
          </el-form-item>
          <el-form-item label="xml源为URL?">
            <el-checkbox true-label="Y" false-label="N" v-model="step.readurl"></el-checkbox>
          </el-form-item>
          <el-form-item label="xml源为文件路径?">
            <el-checkbox true-label="Y" false-label="N" v-model="step.isAFile"></el-checkbox>
          </el-form-item>
          <el-form-item label="xml源">
            <el-select v-model="step.xmlField">
              <el-option v-for="item in step.availableFields" :value="item.name"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="xml元素循环路径">
            <el-input v-model="step.loopxpath"></el-input>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="参数设置" name="second">
        <el-form ref="form2" label-width="150px">
          <el-button icon="plus" @click="_addRecord">添加字段</el-button>
          <br><br>
          <el-table :data="step.fields" stripe border :max-height="300">
            <el-table-column label="名称" :width="120">
              <template scope="scope">
                <div v-if="!scope.row.edit">{{scope.row.name}}</div>
                <div v-else>
                  <el-input v-model="scope.row.name" size="mini"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="xml路径" :width="140">
              <template scope="scope">
                <div v-if="!scope.row.edit">{{scope.row.xpath}}</div>
                <div v-else>
                  <el-input v-model="scope.row.xpath" size="mini"></el-input>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="节点" :width="120">
              <template scope="scope">
                <div v-if="!scope.row.edit">{{scope.row.element_type}}</div>
                <div v-else>
                  <el-select v-model="scope.row.element_type" size="mini">
                    <el-option value="attribut" label="属性"></el-option>
                    <el-option value="node" label="节点"></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="结果类型" :width="130">
              <template scope="scope">
                <div v-if="!scope.row.edit">{{scope.row.result_type}}</div>
                <div v-else>
                  <el-select v-model="scope.row.result_type" size="mini">
                    <el-option value="valueof" label="ValueOf"></el-option>
                    <el-option value="singlenode" label="SingleNode"></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="数据类型" :width="140">
              <template scope="scope">
                <div v-if="!scope.row.edit">{{scope.row.type}}</div>
                <div v-else>
                  <el-select v-model="scope.row.type" size="mini">
                    <el-option v-for="item in options.types" :value="item"></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="去空格" :width="130">
              <template scope="scope">
                <div v-if="!scope.row.edit">{{scope.row.trim_type}}</div>
                <div v-else >
                  <el-select v-model="scope.row.trim_type" size="mini">
                    <el-option v-for="item in options.trimType" :value="item.value" :label="item.name"></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="控制" :width="120">
              <template scope="scope">
                <el-row>
                  <el-col :span="12">
                    <el-button size="mini" type="info" @click="reverseEditState(scope.$index, scope.row)">编辑


                    </el-button>
                  </el-col>
                  <el-col :span="12">
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index)">
                      删除

                    </el-button>
                  </el-col>
                </el-row>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<style scoped lang="scss">
  .el-form-item {
    .el-input, .el-input-number, .el-select {
      width: 350px
    }
  }
</style>
<script>
  import {Steps, Fields, Options} from "../../model/DataModel";
  import StepCommon from "./mixins/StepMixin";

  export default{
    mixins: [StepCommon],
    data(){
      return {
        customParams: {width: "800px"},
        step: Steps.getXMLData(),
        activeName: "first",
        options: {types: Options.inputTypes, trimType: Options.trimType}
      }
    },
    methods: {
      updateFields(){
        this.step.outputFields = this.step.fields.map(el => el.name);
      }
    }
  }
</script>
